package com.ty.skysystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ty.common.utils.PageUtils;
import com.ty.common.utils.Query;
import com.ty.skysystem.dao.TruckDao;
import com.ty.skysystem.entity.TruckEntity;
import com.ty.skysystem.entity.req.TruckEntityREQ;
import com.ty.skysystem.service.TruckService;
import java.util.Map;
import org.springframework.stereotype.Service;

@Service("truckService")
public class TruckServiceImpl extends ServiceImpl<TruckDao, TruckEntity> implements TruckService {

  @Override
  public PageUtils queryPage(Map<String, Object> params) {
    QueryWrapper<TruckEntity> queryWrapper = new QueryWrapper<>();
    // 查询时排除指定列
    queryWrapper.select(TruckEntity.class, e -> !"is_deleted".equals(e.getColumn()));

    if (null != params.get("state")) {
      queryWrapper.eq("state", params.get("state"));
    }
    IPage<TruckEntity> page = this.page(new Query<TruckEntity>().getPage(params), queryWrapper);
    return new PageUtils(page);
  }

  @Override
  public PageUtils unscheduledDispatchBindDriverTruck(
      Integer page, Integer limit, TruckEntityREQ truckEntityREQ) {

    IPage<TruckEntity> truckEntityIPage =
        this.baseMapper.unscheduledDispatchBindDriverTruck(new Page<>(page, limit), truckEntityREQ);
    return new PageUtils(truckEntityIPage);
  }
}
